{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\AppData\\Local\\Temp\\ipykernel_21248\\568616734.py:6: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead\n",
      "  class CustomGraphicsView(QGraphicsView):\n"
     ]
    },
    {
     "ename": "SystemExit",
     "evalue": "0",
     "output_type": "error",
     "traceback": [
      "An exception has occurred, use %tb to see the full traceback.\n",
      "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m 0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\admin\\.conda\\envs\\dl\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3468: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n",
      "  warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "from PyQt5.QtWidgets import QApplication, QGraphicsView, QGraphicsScene, QGraphicsEllipseItem\n",
    "from PyQt5.QtCore import Qt, QRectF\n",
    "from PyQt5.QtGui import QPainter, QPen\n",
    "\n",
    "class CustomGraphicsView(QGraphicsView):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "        self.initUI()\n",
    "\n",
    "    def initUI(self):\n",
    "        # 创建一个QGraphicsScene对象\n",
    "        self.scene = QGraphicsScene(self)\n",
    "        self.setScene(self.scene)\n",
    "\n",
    "        # 设置视图的一些属性\n",
    "        self.setRenderHint(QPainter.Antialiasing)  # 启用抗锯齿\n",
    "        self.setBackgroundBrush(Qt.white)  # 设置背景颜色\n",
    "\n",
    "        # 设置视图的大小和位置\n",
    "        self.setGeometry(300, 300, 400, 300)\n",
    "        self.setWindowTitle('QGraphicsView Mouse Selection Example')\n",
    "\n",
    "    def mousePressEvent(self, event):\n",
    "        # 获取鼠标点击位置\n",
    "        pos = self.mapToScene(event.pos())\n",
    "\n",
    "        # 在场景中添加一个圆形图形项\n",
    "        circle = QGraphicsEllipseItem(pos.x() - 10, pos.y() - 10, 20, 20)\n",
    "        circle.setPen(QPen(Qt.black, 2))\n",
    "        circle.setBrush(Qt.red)\n",
    "        self.scene.addItem(circle)\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app = QApplication(sys.argv)\n",
    "    graphicsView = CustomGraphicsView()\n",
    "    graphicsView.show()\n",
    "    sys.exit(app.exec_())\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "dl",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
